package edu.cqie.common.exception;

import edu.cqie.common.util.ApiResult;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 业务异常处理
     */
    @ExceptionHandler
    public ApiResult businessHandle(BusinessException e) {
        return ApiResult.error(e.getErrorCode(), e.getErrorMessage());
    }

    @ExceptionHandler
    public ApiResult exceptionHandler(RuntimeException e) {
        e.printStackTrace();
        log.error(e.getMessage());
        return ApiResult.error(e.getMessage());
    }


}

